﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细</title>
    <#include "../common/link.ftl">
    <script>
        $(function () {
            $('.btn-input').click(function () {
                // 不刷新页面模态框只是隐藏,内容就一直保留,每次点击前清空
                $("#editForm input").val('');
                //查询a标签的class有没高亮,判断他有没选中
                if(!$("#dic-a a").hasClass("active")){
                    $.messager.popup("请先选中目录");
                    return;
                }

                // 通过事件源.data方法获取自定义属性,会自动封装json详情百度,有则是编辑没有则是添加
                var json = $(this).data("json");
                //把目录的名称设置到模态框
                $("#parentName").val($("#${(qo.parentId)!}").text());
                //把目录的id设置到模态框
                $("#parentId").val(${(qo.parentId)!});
                if(json){
                    // 给编辑回显目录明细数据(id隐藏)
                    $("#editForm input[name=id]").val(json.id);
                    $("#editForm input[name=title]").val(json.title);
                    $("#editForm input[name=sequence]").val(json.sequence);
                }
                // 点击新增或则编辑弹出模态框
                $('#myModal').modal('show');
            });

            $('.btn-primary').click(function () {
                //点击提交按钮
                //判断有没输入序号
                if ($("#editForm input[name=sequence]").val() == ''){
                    //获取最大序号
                    //最后行
                    var last = $('table tr:last');
                    //最后列,获取他的id值
                    var max = last.find("td:last").get(0).id;
                    //把字符串转化成数值,然后+1设置到表单的序号里
                    $("#editForm input[name=sequence]").val(parseInt(max) + 1);
                }
                //ajaxSubmit方法可以把表单转为异步的表单，马上提交
                $('#editForm').ajaxSubmit(handlerMessage);
            })

            //查询条件中的目录a链接并添加高亮效果
            $("#${(qo.parentId)!}").addClass('active');
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="systemDictionaryItem"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin:20px">
                    <div class="col-xs-3">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <div class="list-group" id="dic-a">
                                   <#list systemDictionarys as dic>
                                       <#--添加id属性用于筛选高亮-->
                                       <a href="/systemDictionaryItem/list.do?parentId=${(dic.id)!}"
                                          id="${(dic.id)!}" class="list-group-item">${(dic.title)!}</a>
                                   </#list>
                                </div>
                            </div>
                        </div>
                    </div>
                    <#-- 有选择字典目录才显示字典明细 -->
                    <#if qo.parentId?? >
                    <div class="col-xs-9">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list.do" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="parentId"  value="${(qo.parentId)!}">
                            <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>标题</th>
                                    <th>序号</th>
                                    <th>操作</th>
                                </tr>
                            <#list (pageResult.list)! as systemDictionaryItem>
                            <tr>
                                <td>${(systemDictionaryItem_index)!+1}</td>
                                <td>${(systemDictionaryItem.title)!}</td>
                                <td>${(systemDictionaryItem.sequence)!}</td>
                                <td id = '${(systemDictionaryItem.sequence)!}'>
                                <#-- 自定义属性封装自身的数据(该行),单引号注意 -->
                                    <a class="btn btn-info btn-xs btn-input btn-update" data-json='${(systemDictionaryItem.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                </td>
                            </tr>
                            </#list>
                            </table>
                         </div>
                    </div>
                    <!--分页-->
                    <#include "../common/page.ftl">
                    </#if>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>
<#-- 新增/编辑模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">字典明细新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate.do" method="post" id="editForm">
                <input type="hidden"  name="id">
                <div class="form-group" style="margin-top: 10px;">
                    <label for="parentId" class="col-sm-3 control-label">字典目录：</label>
                    <div class="col-sm-7">
                        <!-- 显示字典目录的名字 -->
                        <input type="text" class="form-control" id="parentName" name="parentName" readonly>
                        <!-- 提交到后台的parentId -->
                        <input type="hidden" id="parentId" name="parentId">
                    </div>
                </div>
                <div class="form-group" style="margin-top: 10px;">
                    <label for="title" class="col-sm-3 control-label">标题：</label>
                    <div class="col-sm-7">
                        <input type="text" class="form-control" id="title" name="title" placeholder="请输入字典明细标题">
                    </div>
                </div>
                <div class="form-group" style="margin-top: 10px;">
                    <label for="sequence" class="col-sm-3 control-label">序号：</label>
                    <div class="col-sm-7">
                        <input type="text" class="form-control" id="sequence" name="sequence" placeholder="请输入字典明细序号">
                    </div>
                </div>
            </form>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
<#-- 新增/编辑模态框 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">字典明细新增/编辑</h4>
                </div>
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="parentId" class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-7">
                            <!-- 显示字典目录的名字 -->
                            <input type="text" class="form-control" id="parentName" name="parentName" readonly>
                            <!-- 提交到后台的parentId -->
                            <input type="hidden" id="parentId" name="parentId">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="title" class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="title" name="title" placeholder="请输入字典明细标题">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sequence" class="col-sm-3 control-label">序号：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="sequence" name="sequence" placeholder="请输入字典明细序号">
                        </div>
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>
